package com.wqc.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

@Aspect
public class AspectJTest {

    @Pointcut("execution(* *.printClassName(..))")
    public void test() {

    }


    @Before("test()")
    public void beforeTest() {
        System.out.println("beforeTest");
    }

    @After("test()")
    public void afterTest() {
        System.out.println("afterTest");
    }

    @AfterReturning("test()")
    public void afterReturningTest() {
        System.out.println("afterReturningTest");
    }

    @AfterThrowing(throwing = "ex",pointcut = "test()")
    public void afterThrowingTest(Throwable ex) {
        System.out.println("异常："+ex);
        System.out.println("afterThrowingTest");
    }

    @Around("test()")
    public Object aroundTest(ProceedingJoinPoint joinPoint) {
        System.out.println("aroundTest before");
        Object o = null;
        try {
            o = joinPoint.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        System.out.println("aroundTest after");
        return o;
    }

}
